#include "model.h"

Model::Model()
{
    this->maxHeight = 300;
    this->maxWidth = 300;
    this->pointsCount = 0;
    this->points = new struct Point[1];
}

Model::~Model()
{
    clear();
}

//ustawienie liczby generowanych punktów
void Model::setPointsCount(int count)
{
    clear();
    this->pointsCount = count;
    this->points = new Point[this->pointsCount];
}

int Model::getPointsCount()
{
    return this->pointsCount;
}

//generowanie i ustawianie do wyświetlenia wygenerowanych punktów
void Model::generatePoints()
{
    //losowanie liczb
    int x, y;
	#pragma omp parallel for
    for (int i=0; i<this->pointsCount; ++i)
    {
        x = rand() % maxWidth;
        y = rand() % maxHeight;
        if (rand()%2 == 0)
            x = -x;
        if (rand()%2 == 0)
            y = -y;
        this->points[i].x = x;
        this->points[i].y = y;
    }
}

struct Point* Model::getPoints()
{
    return this->points;
}

//czyszczenie punktów
void Model::clear()
{
    if (this->points != NULL)
        delete [] this->points;
    this->pointsCount = 0;
}

